#![feature(proc_macro_hygiene, decl_macro)]

#[macro_use] extern crate rocket;

use proc_macro::bridge::client::Client;

#[get("/")]
fn hello() -> String {
    let client = Client::connect("localhost", "27017")
        .expect("Failed to initialize standalone client.");

    let coll = client.db("cqlibmsg").collection("subscribe_info");

    // Find the document and receive a cursor
    let mut cursor = coll.find(Some(doc.clone()), None)
        .ok().expect("Failed to execute find.");

    let item = cursor.next();
    let mut str = String::from("55");


    // cursor.next() returns an Option<Result<Document>>
    match item {
        Some(Ok(doc)) => match doc.get("title") {
            Some(&Bson::String(ref title)) => str.push_str(title),
            _ => panic!("Expected title to be a string!"),
        },
        Some(Err(_)) => panic!("Failed to get next from server!"),
        None => panic!("Server returned no results!"),
    }
    str
}

fn main() {

    rocket::ignite().mount("/", routes![hello]).launch();

}